<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/icon.css">
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script>

		$(function(){
					
			/*表格初始化*/
			$("#grid").datagrid({
				singleSelect:true,
				fit:true,
				fitColumns:true,
				collapsible:true, 
				striped:true,
				rownumbers:true, 
			    columns:[[    
			    	{field:'CK',checkbox:true},
			        {field:'table_code',title:'表名',width:100,align:'center'},    
			        {field:'field_code',title:'原字段名',width:100,align:'center'},
			        {field:'target_field_code',title:'目标字段名',width:100,align:'center'},
			        {field:'is_join_field',title:'是否连接字段',width:50,align:'center'}, 
			        {field:'data_source',title:'数据来源（从左到右用#号分割）',width:300,align:'left'}
			    ]]
			});
			

			function query(){
				$("#grid").datagrid({
					url:'/dataTransferConfig/fieldTransferConfig/getConfigList',
					method:"POST",
					queryParams: parent.getFormJson($("#search_form"))
				});
			}
			
			//查询按钮
			$("#search_btn").click(query);
			query();
			
			//添加按钮
			$("#add_btn").click(function(){
				$("#add_dialog").dialog({ 
					title: '添加配置',    
					width: 950,    
					height: 300,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							$.post("/dataTransferConfig/fieldTransferConfig/insertConfig",parent.getFormJson($('#add_form')),function(response){
								if(response != 1){
									$.messager.alert('提示','添加了'+response+'条数据');
								}
								$("#add_dialog").dialog('close');
								$("#grid").datagrid('reload');
							})
						
						}
					}]
				});
			});
			
			//修改按钮
			$("#edit_btn").click(function(){
				var rows = $('#grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				 
				
				$("#edit_config_id").textbox("setValue", rows[0].config_id);
				$("#edit_table_code").textbox("setValue", rows[0].table_code);
				$("#edit_field_code").textbox("setValue", rows[0].field_code);
				$("#edit_target_field_code").textbox("setValue", rows[0].target_field_code);
				$("#edit_is_join_field").textbox("setValue", rows[0].is_join_field);
				$("#edit_data_source").textbox("setValue", rows[0].data_source);
				
				
				
				$("#edit_dialog").dialog({ 
					title: '修改配置',    
					width: 950,    
					height: 300,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
						
							$.post("/dataTransferConfig/fieldTransferConfig/updateConfig",parent.getFormJson($('#edit_form')),function(response){
								//$.messager.alert('提示','修改了'+response+'条数据');
								$("#edit_dialog").dialog('close');
								$("#grid").datagrid('reload');
							})
						
						}
					}]
				});
				
			});
			
			
			//删除按钮
			$("#del_btn").click(function(){
				var rows = $('#grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				$.post("/dataTransferConfig/fieldTransferConfig/deleteConfig",{config_id:rows[0].config_id},function(response){
					$.messager.alert('提示','删除了'+response+'条数据');
					$("#grid").datagrid('reload');
				})
			});
			
			
		});
			
		</script>
	</head>
	<body class="easyui-layout">
		
		<!-- 查询条件表单 -->
		<div region="north" border="false"   style="width:100%;height:80px;margin-top: 20px;" >
			<form id ="search_form" method="post" class="easyui-form">
				<table width="100%">
					<tr>
						<td align="right" width="15%">表名称:</td>
						<td width="15%"  align="left" >
							<input class="easyui-textbox"  name="table_code" style="width:200px"  />
						</td>
						<td width="15%" ></td>
					</tr>
				</table>

			</form>
			
			<a href="#" id="search_btn" class="easyui-linkbutton"	 data-options="iconCls:'icon-search'"  >查询</a>
			<a href="#" id='add_btn' class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增</a>
			<a href="#" id='edit_btn' class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>
			<a href="#" id='del_btn' class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">删除</a>
		</div>
		
		
		
		<!-- 主表格 -->
		<div region="center" border="false">
			
			<table id="grid" ></table>
		</div>
		
		
		
		<!-- 一些隐藏的对话框 -->
		<!-- 新增子类页 -->
		<div style="display:none" id="add_dialog">
			<form id ="add_form" method="post" >
				<table width="100%">
					<tr>
						<td align="right" width="20%">表名称:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"   name="table_code" style="width:700px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">字段名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="field_code"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">目标字段名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="target_field_code"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">是否连接字段:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="is_join_field"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">数据来源:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="data_source"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div>
		
		<!-- 修改子类页 -->
		<div style="display:none" id="edit_dialog">
			<form id ="edit_form" method="post" >   
				<table width="100%">
					
					<tr style="display:none">
						<td align="right" width="20%">id:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id="edit_config_id"  name="config_id" style="width:700px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">表名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_table_code"  name="table_code"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">字段名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_field_code"  name="field_code"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">目标字段名称:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_target_field_code"  name="target_field_code"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">是否连接字段:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_is_join_field" name="is_join_field"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">数据来源:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox" id="edit_data_source" name="data_source"  style="width:700px">
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div> 
		
		
	</body>
</html>
